package com.eveinfo.api.utils.certificates;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;

public class ApiCategory implements Serializable, Comparable<ApiCategory>{

	private static final long serialVersionUID = 2283200039087444457L;

	private final int ID;
	private final String name;
	private final ArrayList<ApiClass> classes;
	
	public ApiCategory(int ID, String name) {
		this.classes = new ArrayList<ApiClass>(11);
		this.ID = ID;
		this.name = name;
	}

	public int getID() {
		return ID;
	}
	
	public String getName() {
		return name;
	}

	public boolean addClass(ApiClass c){
		return classes.add(c);
	}
	
	public ArrayList<ApiClass> getClasses() {
		return classes;
	}
	
	public ApiClass getClass(int pos){
		return classes.get(pos);
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		for(ApiClass c : classes){
			sb.append(name+"\n");
			sb.append(c);
		}
		return sb.toString();
	}

	public ApiCertificate getCertificate(int certificateID) {
		ApiCertificate certificate = null;
		for(ApiClass c : classes){
			certificate = c.getCertificate(certificateID);
			if(certificate != null){
				break;
			}
		}
		return certificate;
	}

	@Override
	public int compareTo(ApiCategory o) {
		return name.compareTo(o.getName());
	}
	
	public void sort(){
		Collections.sort(classes);
	}
	
}
